#!coding=utf-8
'''
Created on 2015-12-14

@author: Administrator
'''
from django.contrib import admin
from weixin.models import User, ContestantInfo
from shop.models import Catagory, Goods, Order, OrderItem, CustAssess, Brand,\
    CustAdr,Format, SaleInfo, CardInfo, CardItem, Deduction, DeductionItem,\
    Catagory_T
from chat.models import Servicer
    
class Goods_admin(admin.ModelAdmin):
    list_display=('name','get_brand_name','get_catagory_name','sales','stock')
    
    list_filter=('sales','catagory','brand')
    
    search_fields=('name',)
    
    def get_brand_name(self, obj):  
        return obj.brand.name  
    get_brand_name.short_description = '品牌'
    
    def get_catagory_name(self, obj):  
        return obj.catagory.name  
    get_catagory_name.short_description = '商品种类'

class Format_admin(admin.ModelAdmin):
    #type choices的时候，用catagory的方式刷选
    list_display=('get_good_name','get_catagory_display','formatname','stock','price')
    
#     list_filter=('good',)
#     
    def get_good_name(self, obj):  
        return obj.good.name  
    get_good_name.short_description = '商品名称'
    
    search_fields = ('catagory','good__name',) 
class Order_admin(admin.ModelAdmin):
    #type choices的时候，用catagory的方式刷选
    list_display=('id','get_status_display','custname','phoneno','create_at')
    
    list_filter=('status','create_at')
    
    search_fields = ('phoneno','custname',) 
#     def get_good_name(self, obj):  
#         return obj.good.name  
#     get_good_name.short_description = '订单名称'

class SaleInfo_admin(admin.ModelAdmin):
    #type choices的时候，用catagory的方式刷选
    list_display=('id','salename')
class CustAdr_admin(admin.ModelAdmin):
    #type choices的时候，用catagory的方式刷选
    list_display=('custname','phoneno','cityname')    
    search_fields = ('phoneno','custname',) 
class Servicer_admin(admin.ModelAdmin):
    #type choices的时候，用catagory的方式刷选
    list_display=('nickname','status','telephone')  
    
class User_admin(admin.ModelAdmin):
    #type choices的时候，用catagory的方式刷选
    list_display=('name','nickname','openid','telephone')
    search_fields = ('telephone','address','nickname','name',) 
class CardItem_admin(admin.ModelAdmin):
    #type choices的时候，用catagory的方式刷选
    list_display=('openid','get_cardinfo_name','status')
    search_fields = ('openid','status') 
    def get_cardinfo_name(self, obj):  
        return obj.cardinfo.name  
    get_cardinfo_name.short_description = '卡券名称'
    
class ContestantInfo_admin(admin.ModelAdmin):
    #type choices的时候，用catagory的方式刷选
    list_display=('get_name','entries','experience','agerange','reason')
    
    search_fields = ('user','address','nickname',)     
    def get_name(self, obj):  
        return obj.user.name  
    get_name.short_description = '姓名'
    
    def get_tel(self, obj):  
        return obj.user.telephone  
    get_name.short_description = '手机号'
    
admin.site.register(User,User_admin)
admin.site.register(ContestantInfo,ContestantInfo_admin)
admin.site.register(Catagory_T)
admin.site.register(Catagory)
admin.site.register(Brand)
admin.site.register(Goods,Goods_admin)
admin.site.register(Order,Order_admin)
admin.site.register(OrderItem)
admin.site.register(CustAssess)
admin.site.register(CustAdr,CustAdr_admin)
admin.site.register(SaleInfo,SaleInfo_admin)
admin.site.register(Format,Format_admin)
admin.site.register(CardInfo)
admin.site.register(CardItem,CardItem_admin)
admin.site.register(Deduction)
admin.site.register(DeductionItem)
admin.site.register(Servicer,Servicer_admin)
